#include <iostream>
#include <map>
#include <cmath>

std::map<std::string, int> wordToNumber = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
    {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
    {"eight", 8}, {"nine", 9}
};

bool isPrime(int num) {
    if (num < 2) return false;
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

    int number = wordToNumber[word1] * 100 + wordToNumber[word2] * 10 + wordToNumber[word3];

    if (number < 100 || number > 999) {
        std::cout << "Wrong input";
        return 0;
    }

    int lowerPrime = number, upperPrime = number;
    while (!isPrime(lowerPrime)) {
        --lowerPrime;
    }
    while (!isPrime(upperPrime)) {
        ++upperPrime;
    }

    int closestPrime = (number - lowerPrime <= upperPrime - number) ? lowerPrime : upperPrime;
    std::cout << closestPrime;

    return 0;
}
